package com.rs.controller.Rs;

import java.awt.Font;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.KeyAdapter;
import java.awt.event.KeyEvent;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.beans.PropertyVetoException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Optional;

import javax.swing.ButtonGroup;
import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JDesktopPane;
import javax.swing.JDialog;
import javax.swing.JInternalFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JRadioButton;
import javax.swing.JTable;
import javax.swing.JTextField;
import javax.swing.ListSelectionModel;
import javax.swing.table.DefaultTableModel;

import com.rs.model.CommonResult;
import com.rs.model.Department;
import com.rs.model.Position;
import com.rs.model.rs.User;
import com.rs.service.rs.DepartmentService;
import com.rs.service.rs.PositionService;
import com.rs.service.rs.UserService;
import com.rs.util.DateChooser;
import com.rs.util.ImagePanel;
import com.rs.util.SpringContextUtils;
import com.rs.util.TimeTypeConversionUtil;

public class UserJFrame extends JInternalFrame {
	private static final long serialVersionUID = 1L;

	public UserJFrame() {

		//设置是否允许自由调整大小
		setResizable(true);

		//设置是否提供“最大化”按钮
		setMaximizable(true);

		//设置是否提供“最小化”按钮
		setIconifiable(true);

		//设置是否提供关闭按钮
		setClosable(true);
		getContentPane().setLayout(null);

		setVisible(true);
	}

	public void alert(String alert) {
		JOptionPane.showMessageDialog(this, alert);

	}

	/********************添加用户*************************/
	class AddUser extends UserJFrame {

		private DepartmentService ds = SpringContextUtils.getBean(DepartmentService.class);

		private PositionService ps = SpringContextUtils.getBean(PositionService.class);

		private UserService us = SpringContextUtils.getBean(UserService.class);

		private JPanel contentPane;

		private ButtonGroup bg;//单选按钮组

		private static final long serialVersionUID = 1L;

		private JTextField text_name;//姓名

		private JTextField text_sex;//性别

		private JTextField text_age;//年龄

		private JTextField text_birthday;//生日

		private JTextField text_addess;//地址

		private JTextField text_bankNumber;//银行卡号

		private JTextField text_card;//身份证号

		private JTextField text_phone;//手机号

		private JTextField text_email;//电子邮件

		private JComboBox<String> text_de;//部门

		private JComboBox<String> text_po;//职位

		private boolean flag = true;//进行非空验证

		private boolean mouse = false;//鼠标事件

		private String msg = null;//弹出的消息

		Map<String, Integer> mapde = new HashMap<>();
		Map<String, Integer> mappo = new HashMap<>();

		public AddUser() {
			super();
			//设置标题
			setTitle("添加员工");
			//设置是否允许自由调整大小
			setResizable(false);
			//设置最大化
			setMaximizable(false);
			//设置大小
			setBounds(250, 25, 450, 600);
			//主体
			contentPane = new ImagePanel(450, 600, "twwe2.jpg");
			contentPane.setLayout(null);
			setContentPane(contentPane);

			//创建1个字体实例
			Font font = new Font("宋体", Font.BOLD, 14);

			alert("初始密码为身份证后六位");

			//面板的鼠标事件,非空验证
			addMouseListener(new MouseAdapter() {
				@Override
				public void mouseExited(MouseEvent e) {// 鼠标退出组件
					if (mouse) {
						//alert(msg);
						mouse = false;
						flag = true;
					}
				}
			});

			//姓名	
			JLabel name = new JLabel("姓  名：");
			name.setFont(font);
			name.setBounds(130, 25, 80, 20);
			text_name = new JTextField("姓名不能为空");
			text_name.setBounds(210, 25, 100, 20);
			text_name.setColumns(10);
			contentPane.add(name);
			contentPane.add(text_name);

			text_name.addMouseListener(new MouseAdapter() {

				@Override
				public void mouseReleased(MouseEvent e) {// 鼠标松开组件
					System.out.println("gettext:" + text_name.getText());
					if (text_name.getText() == null || "".equals(text_name.getText().trim())) {
						msg = "姓名不能为空";
						mouse = true;
					} else {
						flag = false;
					}
				}

			});

			//性别
			JLabel sex = new JLabel("性  别：");
			sex.setFont(font);
			sex.setBounds(130, 70, 80, 20);
			text_sex = new JTextField();
			bg = new ButtonGroup(); //创建单选按钮组

			JLabel nan = new JLabel("男");
			nan.setFont(font);
			nan.setBounds(200, 70, 40, 20);
			//创建单选按钮
			final JRadioButton male = new JRadioButton("男"); //创建单选按钮
			male.setBounds(230, 70, 20, 20);

			JLabel nv = new JLabel("女");
			nv.setFont(font);
			nv.setBounds(260, 70, 40, 20);
			//创建单选按钮
			final JRadioButton female = new JRadioButton("女");
			female.setBounds(290, 70, 20, 20);

			bg.add(male); //把单选按钮添加到组中
			bg.add(female);
			contentPane.add(sex);
			contentPane.add(nan);
			contentPane.add(nv);
			contentPane.add(male);
			contentPane.add(female);

			//男
			male.addMouseListener(new MouseAdapter() {

				@Override
				public void mouseReleased(MouseEvent e) {// 鼠标松开组件
					if (text_sex.getText() == null || "".equals(text_sex.getText().trim())) {
						msg = "性别不能为空!";
						mouse = true;

					} else {
						flag = false;
					}
				}

				@Override
				public void mousePressed(MouseEvent e) {//点击事件
					text_sex.setText(male.getText());
				}

			});
			//女
			female.addMouseListener(new MouseAdapter() {

				@Override
				public void mouseReleased(MouseEvent e) {// 鼠标松开组件
					if (text_sex.getText() == null || "".equals(text_sex.getText().trim())) {
						msg = "性别不能为空!";
						mouse = true;
					} else {
						flag = false;
					}
				}

				@Override
				public void mousePressed(MouseEvent e) {//点击事件
					text_sex.setText(female.getText());
				}

			});

			//部门
			text_de = new JComboBox<String>();
			text_de.setFont(font);
			text_de.setBounds(130, 120, 100, 20);
			text_de.addItem("部门");
			contentPane.add(text_de);
			List<Department> delist = ds.departmentAll();

			for (Department dd : delist) {
				text_de.addItem(dd.getDe_name());
				mapde.put(dd.getDe_name(), dd.getDe_id());
			}

			//监听器 
			text_de.addMouseListener(new MouseAdapter() {

				@Override
				public void mouseReleased(MouseEvent e) {// 鼠标松开组件
					if (((String) text_de.getSelectedItem()).equals("部门")) {
						msg = "请选择部门!";
						mouse = true;
					} else {
						flag = false;
					}
				}

			});

			text_de.addActionListener(new ActionListener() {

				@Override
				public void actionPerformed(ActionEvent e) {
					String dename = (String) text_de.getSelectedItem();
					//清空text_po
					text_po.removeAllItems();
					text_po.addItem("职位");
					//清空mappo
					mappo.clear();
					if (!dename.equals("部门")) {
						//部门id
						Integer de_id = mapde.get(text_de.getSelectedItem());
						//职位集合
						List<Position> polist = ps.positonBydeid(de_id);
						for (Position pp : polist) {

							text_po.addItem(pp.getPo_name());
							mappo.put(pp.getPo_name(), pp.getPo_id());
						}
					}

				}
			});

			//职位
			text_po = new JComboBox<String>();
			text_po.setFont(font);
			text_po.setBounds(250, 120, 100, 20);
			text_po.addItem("职位");
			contentPane.add(text_po);
			text_po.addMouseListener(new MouseAdapter() {

				@Override
				public void mouseReleased(MouseEvent e) {// 鼠标松开组件
					if (((String) text_po.getSelectedItem()).equals("职位")) {
						msg = "请选择职位!";
						mouse = true;
					} else {
						flag = false;
					}
				}

			});

			//身份证号
			JLabel card = new JLabel("身份证号：");
			card.setFont(font);
			card.setBounds(130, 170, 80, 20);
			text_card = new JTextField("请输入18位身份证号");
			text_card.setBounds(210, 170, 100, 20);
			text_card.setColumns(10);
			contentPane.add(card);
			contentPane.add(text_card);
			text_card.addMouseListener(new MouseAdapter() {

				@Override
				public void mouseReleased(MouseEvent e) {// 鼠标松开组件
					if (text_card.getText() == null || "".equals(text_card.getText().trim())) {
						msg = "身份证不能为空!";
						mouse = true;
						return;
					} else {
						flag = false;
					}

					if (text_card.getText().length() != 18) {
						msg = "请输入18位的身份证号!";
						mouse = true;
					} else {
						flag = false;
					}
				}

			});

			//年龄
			JLabel age = new JLabel("年  龄：");
			age.setFont(font);
			age.setBounds(130, 220, 80, 20);
			text_age = new JTextField("年龄不能为空");
			text_age.setBounds(210, 220, 100, 20);
			text_age.setColumns(10);
			contentPane.add(age);
			contentPane.add(text_age);
			//添加监听器，只能输入数字
			text_age.addKeyListener(new KeyAdapter() {
				@Override
				public void keyTyped(KeyEvent e) {
					int keyChar = e.getKeyChar();
					if (keyChar >= KeyEvent.VK_0 && keyChar <= KeyEvent.VK_9) {

					} else {
						e.consume(); //关键，屏蔽掉非法输入
					}
				}
			});
			text_age.addMouseListener(new MouseAdapter() {

				@Override
				public void mouseReleased(MouseEvent e) {// 鼠标松开组件
					if (text_age.getText() == null || "".equals(text_age.getText().trim())) {
						msg = "年龄不能为空!";
						mouse = true;
					} else {
						flag = false;
					}
				}

			});

			//出生日期
			JLabel birthday = new JLabel("出生日期：");
			birthday.setFont(font);
			birthday.setBounds(130, 270, 80, 20);
			//获得JSPinner对象
			text_birthday = new JTextField();
			text_birthday.setBounds(210, 270, 100, 20);
			text_birthday.setColumns(10);
			text_birthday.setText(TimeTypeConversionUtil.getTimeString("yyyy-MM-dd"));
			//禁止编辑
			text_birthday.setEditable(false);
			contentPane.add(birthday);
			contentPane.add(text_birthday);
			//添加鼠标监听事件
			text_birthday.addMouseListener(new MouseAdapter() {
				//鼠标点击事件
				@Override
				public void mouseClicked(MouseEvent e) {
					final JDialog jDialog = new JDialog();//对话框
					jDialog.setBounds(500, 200, 350, 350);
					jDialog.setResizable(false);
					final DateChooser datePicker = new DateChooser();
					datePicker.addActionListener(new ActionListener() {// 事件捕获
						@Override
						public void actionPerformed(ActionEvent e) {
							String time = datePicker.getSelectedDate();
							text_birthday.setText(time);
							jDialog.dispose();
						}
					});

					jDialog.getContentPane().add(datePicker);
					jDialog.setVisible(true);

				}
			});

			//银行卡号
			JLabel bankNumber = new JLabel("银行卡号：");
			bankNumber.setFont(font);
			bankNumber.setBounds(130, 320, 80, 20);
			text_bankNumber = new JTextField("银行卡不能为空");
			text_bankNumber.setBounds(210, 320, 100, 20);
			text_bankNumber.setColumns(10);
			contentPane.add(bankNumber);
			contentPane.add(text_bankNumber);
			//添加监听器，只能输入数字
			text_bankNumber.addKeyListener(new KeyAdapter() {
				@Override
				public void keyTyped(KeyEvent e) {
					int keyChar = e.getKeyChar();
					if (keyChar >= KeyEvent.VK_0 && keyChar <= KeyEvent.VK_9) {

					} else {
						e.consume(); //关键，屏蔽掉非法输入
					}
				}
			});

			text_bankNumber.addMouseListener(new MouseAdapter() {

				@Override
				public void mouseReleased(MouseEvent e) {// 鼠标松开组件
					if (text_bankNumber.getText() == null || "".equals(text_bankNumber.getText().trim())) {
						msg = "银行卡不能为空!";
						mouse = true;
					} else {
						flag = false;
					}
				}

			});

			//手机号
			JLabel phone = new JLabel("手机号：");
			phone.setFont(font);
			phone.setBounds(130, 370, 80, 20);
			text_phone = new JTextField("请输入11位手机号");
			text_phone.setBounds(210, 370, 100, 20);
			text_phone.setColumns(10);
			contentPane.add(phone);
			contentPane.add(text_phone);

			//添加监听器，只能输入数字
			text_phone.addKeyListener(new KeyAdapter() {
				@Override
				public void keyTyped(KeyEvent e) {
					int keyChar = e.getKeyChar();
					if (keyChar >= KeyEvent.VK_0 && keyChar <= KeyEvent.VK_9) {

					} else {
						e.consume(); //关键，屏蔽掉非法输入
					}
				}
			});

			text_phone.addMouseListener(new MouseAdapter() {

				@Override
				public void mouseReleased(MouseEvent e) {// 鼠标松开组件
					if (text_phone.getText() == null || "".equals(text_phone.getText().trim())) {
						msg = "手机号不能为空!";
						mouse = true;
						return;
					} else {
						flag = false;
					}
					if (text_phone.getText().length() != 11) {
						msg = "请输入11位手机号!";
						mouse = true;
					} else {
						flag = false;
					}
				}

			});

			//电子邮件
			JLabel email = new JLabel("电子邮箱：");
			email.setFont(font);
			email.setBounds(130, 420, 80, 20);
			text_email = new JTextField("电子邮箱不能为空");
			text_email.setBounds(210, 420, 100, 20);
			text_email.setColumns(10);
			contentPane.add(email);
			contentPane.add(text_email);
			text_email.addMouseListener(new MouseAdapter() {

				@Override
				public void mouseReleased(MouseEvent e) {// 鼠标松开组件
					if (text_email.getText() == null || "".equals(text_email.getText().trim())) {
						msg = "电子邮箱不能为空!";
						mouse = true;
						return;
					} else {
						flag = false;
					}
					if (!text_email.getText().matches("\\w*+[@]\\w+[.]\\w*")) {
						msg = "请输入正确的电子邮箱!";
						mouse = true;
					} else {
						flag = false;
					}
				}

			});

			//住址
			JLabel addess = new JLabel("住  址：");
			addess.setFont(font);
			addess.setBounds(130, 470, 80, 20);
			text_addess = new JTextField("住址不能为空");
			text_addess.setBounds(210, 470, 100, 20);
			text_addess.setColumns(10);
			contentPane.add(addess);
			contentPane.add(text_addess);
			text_addess.addMouseListener(new MouseAdapter() {

				@Override
				public void mouseReleased(MouseEvent e) {// 鼠标松开组件
					if (text_addess.getText() == null || "".equals(text_addess.getText().trim())) {
						msg = "住址不能为空!";
						mouse = true;
					} else {
						flag = false;
					}
				}

			});

			//确认按钮
			JButton yesButton = new JButton("确认");
			yesButton.setFont(font);
			yesButton.setBounds(130, 510, 70, 25);
			contentPane.add(yesButton);
			//监听
			yesButton.addActionListener(new ActionListener() {
				@Override
				public void actionPerformed(ActionEvent e) {
					yanzheng();

					//验证
					if (flag) {
						alert("请按照正确格式填写！");
						return;
					}
					//获取值
					User user = new User();
					//姓名
					user.setU_name(text_name.getText());
					//性别
					user.setU_sex(text_sex.getText());
					//身份证
					user.setU_idcard(text_card.getText());
					//年龄
					user.setU_age(Integer.valueOf(text_age.getText()));
					//生日
					user.setU_birthday(TimeTypeConversionUtil.getDateByString(text_birthday.getText()));
					//手机号
					user.setU_phone(text_phone.getText());
					//电子邮件
					user.setU_email(text_email.getText());
					//银行卡号
					user.setU_bankNumber(text_bankNumber.getText());
					//住址
					user.setU_address(text_addess.getText());
					//部门id
					user.setU_deid(mapde.get(text_de.getSelectedItem()));
					//职务id
					user.setU_poid(mappo.get(text_po.getSelectedItem()));

					CommonResult<String> userAddEmpPc = us.userAddEmpPc(user);
					alert(userAddEmpPc.getMessage());
					reset();

				}
			});

			//重置按钮
			JButton resetButton = new JButton("重置");
			resetButton.setFont(font);
			resetButton.setBounds(240, 510, 70, 25);
			contentPane.add(resetButton);
			//监听
			resetButton.addActionListener(new ActionListener() {
				@Override
				public void actionPerformed(ActionEvent e) {
					reset();

				}
			});

		}

		//重置
		public void reset() {
			//姓名
			text_name.setText("姓名不能为空");
			//手机号
			text_phone.setText("请输入11位手机号");
			//身份证
			text_card.setText("请输入18位身份证号");
			//性别
			bg.clearSelection();
			//年龄
			text_age.setText("年龄不能为空");
			//地址
			text_addess.setText("地址不能为空");
			//电子邮件
			text_email.setText("电子邮件不能为空");
			//银行卡
			text_bankNumber.setText("银行卡不能为空");
			//部门
			text_de.setSelectedIndex(0);
			//职务
			text_po.setSelectedIndex(0);

		}

		public void yanzheng() {
			if (text_name.getText().equals("姓名不能为空") || text_name.getText().equals("")) {
				flag = true;
				return;
			}
			if (text_phone.getText().equals("请输入11位手机号") || text_phone.getText().equals("")) {
				flag = true;
				return;
			}
			if (text_card.getText().equals("请输入18位身份证号") || text_card.getText().equals("")) {
				flag = true;
				return;
			}
			if (text_age.getText().equals("年龄不能为空") || text_age.getText().equals("")) {
				flag = true;
				return;
			}
			if (text_email.getText().equals("地址不能为空") || text_email.getText().equals("")) {
				flag = true;
				return;
			}
			if (text_bankNumber.getText().equals("银行卡不能为空") || text_bankNumber.getText().equals("")) {
				flag = true;
				return;
			}

		}

	}

	/**********************查询用户*****************************************/
	class QueryUser extends UserJFrame {

		private UserService us = SpringContextUtils.getBean(UserService.class);

		private DepartmentService ds = SpringContextUtils.getBean(DepartmentService.class);

		private PositionService ps = SpringContextUtils.getBean(PositionService.class);

		private User user = new User();

		private JPanel contentPane;

		private JTable table;

		// 表头（列名）
		private Object[] columnNames = { "ID", "姓名", "性别", "部门", "职务", "状态", "就职时间", "审核", "操作" };

		private DefaultTableModel dtable;

		private JLabel show;//显示分页

		private Integer pageNum;//当前页

		//private Integer total;//总条数

		private Integer pages;//总页数

		private JTextField name;//姓名

		private JComboBox<String> de;//部门

		private JComboBox<String> po;//职位

		private JComboBox<String> audit;//审核状态

		private JComboBox<String> type;//就职状态

		Map<String, Integer> mapde = new HashMap<>();
		Map<String, Integer> mappo = new HashMap<>();

		private static final long serialVersionUID = 1L;

		public QueryUser(final JDesktopPane q) {
			super();
			//设置标题
			setTitle("查询员工");
			//设置是否允许自由调整大小
			setResizable(false);
			//设置最大化
			setMaximizable(false);
			//设置大小
			setBounds(40, 35, 800, 550);
			//主体
			contentPane = new ImagePanel(800, 550, "twwe2.jpg");
			contentPane.setLayout(null);
			setContentPane(contentPane);

			//创建1个字体实例
			Font font = new Font("宋体", Font.BOLD, 14);
			//初始化当前页数为
			user.setPageNum(1);
			//查询所有的员工
			CommonResult<Map<String, Object>> users = us.userConditionQueryPc(user);

			//为当前页赋值
			pageNum = (Integer) users.getData().get("pageNum");
			//总条数
			//total = (Integer) users.getData().get("total");
			//总页数
			pages = (Integer) users.getData().get("pages");
			//转为list
			@SuppressWarnings("unchecked")
			List<User> uList = (List<User>) users.getData().get("list");

			// 表格所有行数据
			Object[][] rowData = new Object[uList.size()][];

			for (int i = 0, n = uList.size(); i < n; i++) {
				User u = uList.get(i);
				rowData[i] = u.toObjects();

			}

			// 创建一个表格，指定 所有行数据 和 表头
			dtable = new DefaultTableModel(rowData, columnNames);

			table = new JTable(dtable) {
				private static final long serialVersionUID = 1L;

				//设置表格为不可编辑
				@Override
				public boolean isCellEditable(int row, int column) {
					return false;
				}
			};
			//设置行高
			table.setRowHeight(25);
			table.setFont(font);
			table.getTableHeader().setBounds(20, 90, 750, 25);
			table.setBounds(20, 120, 750, 300);
			//表头不可拖动
			table.getTableHeader().setReorderingAllowed(false);
			//设置是否可以选择此模型中的行。 
			table.setRowSelectionAllowed(true);
			//设置表格为不可编辑
			//table.isCellEditable(uList.size(), 6);
			//设置只能选择一行
			table.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
			//设置选中行的背景色
			//table.setSelectionBackground(Color.black);
			//设置选中行的前景色
			//table.setSelectionForeground(Color.black);+0
			//添加按钮

			//添加按钮
			/*table.getColumnModel().getColumn(6).setCellRenderer(new TableCellRenderer() {
				@Override
				public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected,
						boolean hasFocus, int row, int column) {
					JButton button = new JButton();
					button.setSize(25, 20);
					button.setText("查看");
					button.setFont(font);
					return button;
				}
			});*/
			// 把 表头 添加到容器顶部（使用普通的中间容器添加表格时，表头 和 内容 需要分开添加）
			contentPane.add(table.getTableHeader(), null);
			// 把 表格内容 添加到容器中心
			contentPane.add(table, null);

			//表格的点击事件

			table.addMouseListener(new MouseAdapter() {

				@Override
				public void mouseClicked(MouseEvent e) {
					if (e.getClickCount() == 2) {
						// 处理鼠标双击
						int row = table.getSelectedRow();
						String uId = table.getValueAt(row, 0).toString(); //得到所在行的第一个列的值，作为下面事件传递的参数
						try {
							//使窗口图标化
							setIcon(true);
						} catch (PropertyVetoException e1) {

							e1.printStackTrace();
						}
						q.add(new UserJFrame().new DetailsUser(uId, q));
					}
				}

			});

			//分页

			show = new JLabel();
			show.setText("当前页：" + pageNum + " / 总页数：" + pages);
			show.setFont(new Font("宋体", Font.BOLD, 16));
			show.setBounds(300, 420, 200, 30);
			contentPane.add(show, null);

			final JButton fore = new JButton("首  页");
			fore.setBounds(100, 475, 80, 28);
			fore.setFont(font);
			contentPane.add(fore, null);
			fore.addActionListener(new ActionListener() {
				@Override
				public void actionPerformed(ActionEvent e) {
					String type = fore.getText();
					paging(type);

				}
			});

			final JButton previous = new JButton("上一页");
			previous.setBounds(280, 475, 80, 28);
			previous.setFont(font);
			contentPane.add(previous, null);
			previous.addActionListener(new ActionListener() {
				@Override
				public void actionPerformed(ActionEvent e) {
					String type = previous.getText();
					paging(type);

				}
			});

			final JButton later = new JButton("下一页");
			later.setBounds(470, 475, 80, 28);
			later.setFont(font);
			contentPane.add(later, null);
			later.addActionListener(new ActionListener() {
				@Override
				public void actionPerformed(ActionEvent e) {
					String type = later.getText();
					paging(type);

				}
			});

			final JButton aft = new JButton("尾  页");
			aft.setBounds(630, 475, 80, 28);
			aft.setFont(font);
			contentPane.add(aft, null);
			aft.addActionListener(new ActionListener() {
				@Override
				public void actionPerformed(ActionEvent e) {
					String type = aft.getText();
					paging(type);

				}
			});

			name = new JTextField("姓名", 10);
			name.setBounds(20, 10, 90, 20);
			name.setFont(font);
			contentPane.add(name, null);

			//部门
			de = new JComboBox<String>();
			de.setFont(font);
			de.setBounds(130, 10, 90, 20);
			de.addItem("部门");
			contentPane.add(de);
			List<Department> delist = ds.departmentAll();

			for (Department dd : delist) {
				de.addItem(dd.getDe_name());
				mapde.put(dd.getDe_name(), dd.getDe_id());
			}

			de.addActionListener(new ActionListener() {

				@Override
				public void actionPerformed(ActionEvent e) {
					String dename = (String) de.getSelectedItem();
					//清空text_po
					po.removeAllItems();
					po.addItem("职位");
					//清空mappo
					mappo.clear();
					if (!dename.equals("部门")) {
						//部门id
						Integer de_id = mapde.get(de.getSelectedItem());
						//职位集合
						List<Position> polist = ps.positonBydeid(de_id);
						for (Position pp : polist) {

							po.addItem(pp.getPo_name());
							mappo.put(pp.getPo_name(), pp.getPo_id());
						}
					}

				}
			});
			//职位
			po = new JComboBox<String>();
			po.setFont(font);
			po.setBounds(240, 10, 90, 20);
			po.addItem("职位");
			contentPane.add(po);

			//审核
			String[] audytArr = new String[] { "审核状态", "未审核", "通过", "驳回" };
			audit = new JComboBox<String>(audytArr);
			audit.setBounds(350, 10, 90, 20);
			audit.setFont(font);
			contentPane.add(audit);

			//审核
			String[] typeArr = new String[] { "就职状态", "实习", "入职", "离职" };
			type = new JComboBox<String>(typeArr);
			type.setBounds(460, 10, 90, 20);
			type.setFont(font);
			contentPane.add(type);

			//查询按钮
			JButton query = new JButton("查询");
			query.setBounds(590, 10, 70, 20);
			query.setFont(font);
			contentPane.add(query);
			query.addActionListener(new ActionListener() {

				@Override
				public void actionPerformed(ActionEvent e) {
					//姓名
					if (!name.getText().equals("姓名")) {

						user.setU_name(name.getText());
					}
					//部门id
					if (!de.getSelectedItem().equals("部门")) {

						user.setU_deid(mapde.get(de.getSelectedItem()));
					}
					//职务id
					if (!po.getSelectedItem().equals("职位")) {

						user.setU_poid(mappo.get(po.getSelectedItem()));
					}
					//审核状态
					String auditString = (String) audit.getSelectedItem();
					if (!auditString.equals("审核状态")) {
						switch (auditString) {
						case "未审核":
							user.setU_examine(0);
							break;
						case "通过":
							user.setU_examine(1);
							break;
						case "驳回":
							user.setU_examine(2);
							break;

						}
					}

					//就职状态
					String typeString = (String) type.getSelectedItem();
					if (!typeString.equals("就职状态")) {
						switch (typeString) {
						case "实习":
							user.setU_type(0);
							break;
						case "入职":
							user.setU_type(1);
							break;
						case "离职":
							user.setU_type(2);
							break;
						}

					}
					//查询
					//设置当前页为1
					user.setPageNum(1);
					CommonResult<Map<String, Object>> result = us.userConditionQueryPc(user);
					Object[][] shouye = getObjectArys(result);
					//使用数组 dataVector的值替换 dataVector实例变量中的值。 
					dtable.setDataVector(shouye, columnNames);
					table.setModel(dtable);
					pageNum = (Integer) result.getData().get("pageNum");
					pages = (Integer) result.getData().get("pages");
					show.setText("当前页：" + pageNum + " / 总页数：" + pages);

				}
			});

			//重置按钮
			JButton reset = new JButton("重置");
			reset.setBounds(680, 10, 70, 20);
			reset.setFont(font);
			contentPane.add(reset);
			reset.addActionListener(new ActionListener() {

				@Override
				public void actionPerformed(ActionEvent e) {
					//重置
					reset();
				}
			});

		}

		public void paging(String type) {
			switch (type) {
			case "首  页":
				user.setPageNum(1);
				CommonResult<Map<String, Object>> ufore = us.userConditionQueryPc(user);
				Object[][] shouye = getObjectArys(ufore);
				//使用数组 dataVector的值替换 dataVector实例变量中的值。 
				dtable.setDataVector(shouye, columnNames);
				table.setModel(dtable);
				pageNum = (Integer) ufore.getData().get("pageNum");
				pages = (Integer) ufore.getData().get("pages");
				show.setText("当前页：" + pageNum + " / 总页数：" + pages);
				break;
			case "上一页":
				//当前页减1
				int previousNum = pageNum - 1;
				if (previousNum < 1) {
					alert("当前已是首页");
					previousNum = 1;
				}
				user.setPageNum(previousNum);
				CommonResult<Map<String, Object>> upreviou = us.userConditionQueryPc(user);
				Object[][] shangyi = getObjectArys(upreviou);

				//使用数组 dataVector的值替换 dataVector实例变量中的值。 
				dtable.setDataVector(shangyi, columnNames);
				table.setModel(dtable);
				pageNum = (Integer) upreviou.getData().get("pageNum");
				pages = (Integer) upreviou.getData().get("pages");
				show.setText("当前页：" + pageNum + " / 总页数：" + pages);

				break;
			case "下一页":
				//当前页加1
				int laterNum = pageNum + 1;

				if (laterNum > pages) {
					alert("当前已是尾页");
					laterNum = pages;
				}

				user.setPageNum(laterNum);
				CommonResult<Map<String, Object>> ulater = us.userConditionQueryPc(user);
				Object[][] xiayiye = getObjectArys(ulater);

				//使用数组 dataVector的值替换 dataVector实例变量中的值。 
				dtable.setDataVector(xiayiye, columnNames);
				table.setModel(dtable);
				pageNum = (Integer) ulater.getData().get("pageNum");
				pages = (Integer) ulater.getData().get("pages");
				show.setText("当前页：" + pageNum + " / 总页数：" + pages);
				break;
			case "尾  页":
				user.setPageNum(pages);
				CommonResult<Map<String, Object>> uaft = us.userConditionQueryPc(user);
				Object[][] weiye = getObjectArys(uaft);
				//使用数组 dataVector的值替换 dataVector实例变量中的值。 
				dtable.setDataVector(weiye, columnNames);
				table.setModel(dtable);
				pageNum = (Integer) uaft.getData().get("pageNum");
				pages = (Integer) uaft.getData().get("pages");
				show.setText("当前页：" + pageNum + " / 总页数：" + pages);
				break;
			}
		}

		public Object[][] getObjectArys(CommonResult<Map<String, Object>> users) {
			@SuppressWarnings("unchecked")
			List<User> uList = (List<User>) users.getData().get("list");

			Object[][] rowData = new Object[uList.size()][];
			for (int i = 0, n = uList.size(); i < n; i++) {
				User u = uList.get(i);
				rowData[i] = u.toObjects();
			}
			return rowData;
		}

		//重置
		public void reset() {
			//姓名
			name.setText("姓名");
			//部门
			de.setSelectedIndex(0);
			//职务
			po.setSelectedIndex(0);
			//审核
			audit.setSelectedIndex(0);
			//状态
			type.setSelectedIndex(0);
			user.setU_name(null);
			user.setU_deid(null);
			user.setU_poid(null);
			user.setU_examine(null);
			user.setU_type(null);

		}

	}

	/************用户详情***********/
	class DetailsUser extends UserJFrame {

		private static final long serialVersionUID = 1L;
		private JPanel contentPane;
		private UserService us = SpringContextUtils.getBean(UserService.class);

		private JTextField text_id;//id

		private JTextField text_usename;//账号

		private JTextField text_name;//姓名

		private JTextField text_sex;//性别

		private JTextField text_age;//年龄

		private JTextField text_birthday;//生日

		private JTextField text_addess;//地址

		private JTextField text_bankNumber;//银行卡号

		private JTextField text_card;//身份证号

		private JTextField text_phone;//手机号

		private JTextField text_email;//电子邮件

		private JTextField text_de;//部门

		private JTextField text_po;//职位

		private JTextField text_entyy;//入职时间

		private JTextField text_type;//就职状态

		private JTextField text_quit;//离职时间

		private JTextField text_audit;//审核

		private JTextField text_aname;//审核人

		public DetailsUser(String uid, JDesktopPane q) {
			super();
			//使窗体只有一个界面
			JInternalFrame[] jif = q.getAllFrames();
			if (jif.length >= 2) {
				jif[0].dispose();
			}
			//设置标题
			setTitle("员工详情");
			//设置是否允许自由调整大小
			setResizable(false);
			//设置最大化
			setMaximizable(false);
			//设置大小
			setBounds(150, 30, 600, 580);

			contentPane = new ImagePanel(600, 580, "twwe2.jpg");
			contentPane.setLayout(null);
			setContentPane(contentPane);

			//查询user
			User user = us.userQueryOneEmpPc(Integer.valueOf(uid)).getData();

			//初始化字体
			Font font = new Font("宋体", Font.BOLD, 15);
			//姓名
			JLabel name = new JLabel("员工姓名:");
			name.setFont(font);
			name.setBounds(50, 30, 75, 20);
			text_name = new JTextField(user.getU_name());
			text_name.setFont(font);
			text_name.setBounds(130, 30, 80, 20);
			//禁止编辑
			text_name.setEditable(false);
			contentPane.add(name);
			contentPane.add(text_name);

			//id
			JLabel id = new JLabel("员工ID:");
			id.setFont(font);
			id.setBounds(50, 70, 75, 20);
			text_id = new JTextField(String.valueOf(user.getU_id()));
			text_id.setFont(font);
			text_id.setBounds(130, 70, 80, 20);
			//禁止编辑
			text_id.setEditable(false);
			contentPane.add(id);
			contentPane.add(text_id);

			//账号
			JLabel usename = new JLabel("员工账号:");
			usename.setFont(font);
			usename.setBounds(50, 120, 75, 20);
			text_usename = new JTextField(user.getU_username());
			text_usename.setFont(font);
			text_usename.setBounds(130, 120, 120, 20);
			//禁止编辑
			text_usename.setEditable(false);
			contentPane.add(usename);
			contentPane.add(text_usename);

			//性别
			JLabel sex = new JLabel("员工性别:");
			sex.setFont(font);
			sex.setBounds(50, 170, 75, 20);
			text_sex = new JTextField(user.getU_sex());
			text_sex.setFont(font);
			text_sex.setBounds(130, 170, 80, 20);
			//禁止编辑
			text_sex.setEditable(false);
			contentPane.add(sex);
			contentPane.add(text_sex);

			//年龄
			JLabel age = new JLabel("员工年龄:");
			age.setFont(font);
			age.setBounds(50, 220, 75, 20);
			text_age = new JTextField(String.valueOf(user.getU_age()));
			text_age.setFont(font);
			text_age.setBounds(130, 220, 80, 20);
			//禁止编辑
			text_age.setEditable(false);
			contentPane.add(age);
			contentPane.add(text_age);

			//生日
			JLabel birthday = new JLabel("员工生日:");
			birthday.setFont(font);
			birthday.setBounds(50, 270, 75, 20);
			text_birthday = new JTextField(TimeTypeConversionUtil.getStringDate(user.getU_birthday()));
			text_birthday.setFont(font);
			text_birthday.setBounds(130, 270, 100, 20);
			//禁止编辑
			text_birthday.setEditable(false);
			contentPane.add(birthday);
			contentPane.add(text_birthday);

			//地址
			JLabel addess = new JLabel("员工地址:");
			addess.setFont(font);
			addess.setBounds(50, 320, 75, 20);
			text_addess = new JTextField(user.getU_address());
			text_addess.setFont(font);
			text_addess.setBounds(130, 320, 165, 20);
			//禁止编辑
			text_addess.setEditable(false);
			contentPane.add(addess);
			contentPane.add(text_addess);

			//手机号
			JLabel phone = new JLabel("手机号:");
			phone.setFont(font);
			phone.setBounds(50, 370, 75, 20);
			text_phone = new JTextField(user.getU_phone());
			text_phone.setFont(font);
			text_phone.setBounds(130, 370, 120, 20);
			//禁止编辑
			text_phone.setEditable(false);
			contentPane.add(phone);
			contentPane.add(text_phone);

			//身份证号
			JLabel card = new JLabel("身份证号:");
			card.setFont(font);
			card.setBounds(50, 420, 75, 20);
			text_card = new JTextField(user.getU_idcard());
			text_card.setFont(font);
			text_card.setBounds(130, 420, 185, 20);
			//禁止编辑
			text_card.setEditable(false);
			contentPane.add(card);
			contentPane.add(text_card);

			//银行卡号
			JLabel bankNumber = new JLabel("银行卡号:");
			bankNumber.setFont(font);
			bankNumber.setBounds(50, 470, 75, 20);
			text_bankNumber = new JTextField(user.getU_bankNumber());
			text_bankNumber.setFont(font);
			text_bankNumber.setBounds(130, 470, 185, 20);
			//禁止编辑
			text_bankNumber.setEditable(false);
			contentPane.add(bankNumber);
			contentPane.add(text_bankNumber);

			//电子邮件
			JLabel email = new JLabel("电子邮箱:");
			email.setFont(font);
			email.setBounds(300, 30, 75, 20);
			text_email = new JTextField(user.getU_email());
			text_email.setFont(font);
			text_email.setBounds(380, 30, 180, 20);
			//禁止编辑
			text_email.setEditable(false);
			contentPane.add(email);
			contentPane.add(text_email);

			//部门
			JLabel de = new JLabel("员工部门:");
			de.setFont(font);
			de.setBounds(300, 70, 75, 20);
			text_de = new JTextField(user.getU_dename());
			text_de.setFont(font);
			text_de.setBounds(380, 70, 80, 20);
			//禁止编辑
			text_de.setEditable(false);
			contentPane.add(de);
			contentPane.add(text_de);

			//职位
			JLabel po = new JLabel("员工职位:");
			po.setFont(font);
			po.setBounds(300, 120, 75, 20);
			text_po = new JTextField(user.getU_poname());
			text_po.setFont(font);
			text_po.setBounds(380, 120, 80, 20);
			//禁止编辑
			text_po.setEditable(false);
			contentPane.add(po);
			contentPane.add(text_po);

			//就职状态
			JLabel type = new JLabel("就职状态:");
			type.setFont(font);
			type.setBounds(300, 170, 75, 20);
			String u_type = "";
			if (Optional.ofNullable(user.getU_type()).isPresent()) {

				switch (user.getU_type()) {
				case 0:
					u_type = "实习";
					break;
				case 1:
					u_type = "入职";
					break;
				case 2:
					u_type = "离职";
					break;
				}
			}
			text_type = new JTextField(u_type);
			text_type.setFont(font);
			text_type.setBounds(380, 170, 80, 20);
			//禁止编辑
			text_type.setEditable(false);
			contentPane.add(type);
			contentPane.add(text_type);

			//入职时间
			JLabel entyy = new JLabel("入职时间:");
			entyy.setFont(font);
			entyy.setBounds(300, 220, 75, 20);

			text_entyy = new JTextField(TimeTypeConversionUtil.getStringDate(user.getU_entryTime()));
			text_entyy.setFont(font);
			text_entyy.setBounds(380, 220, 100, 20);
			//禁止编辑
			text_entyy.setEditable(false);
			contentPane.add(entyy);
			contentPane.add(text_entyy);

			//离职时间
			JLabel quit = new JLabel("离职时间:");
			quit.setFont(font);
			quit.setBounds(300, 270, 75, 20);

			text_quit = new JTextField(TimeTypeConversionUtil.getStringDate(user.getU_quitTime()));
			text_quit.setFont(font);
			text_quit.setBounds(380, 270, 100, 20);
			//禁止编辑
			text_quit.setEditable(false);
			contentPane.add(quit);
			contentPane.add(text_quit);

			//审核状态
			JLabel audit = new JLabel("审核状态:");
			audit.setFont(font);
			audit.setBounds(300, 320, 75, 20);

			String audit_type = "";
			if (Optional.ofNullable(user.getU_examine()).isPresent()) {

				switch (user.getU_examine()) {
				case 0:
					audit_type = "未审核";
					break;
				case 1:
					audit_type = "通过";
					break;
				case 2:
					audit_type = "驳回";
					break;
				}
			}

			text_audit = new JTextField(audit_type);
			text_audit.setFont(font);
			text_audit.setBounds(380, 320, 100, 20);
			//禁止编辑
			text_audit.setEditable(false);
			contentPane.add(audit);
			contentPane.add(text_audit);

			//审核人

			JLabel aname = new JLabel("审核人:");
			aname.setFont(font);
			aname.setBounds(300, 370, 75, 20);

			text_aname = new JTextField(user.getU_uname());
			text_aname.setFont(font);
			text_aname.setBounds(380, 370, 80, 20);
			//禁止编辑
			text_aname.setEditable(false);
			contentPane.add(aname);
			contentPane.add(text_aname);

		}

	}
}
